package com.etrans.util;

import java.util.Random;

/**
 * 随机数生成
 *
 */
public class RandomUtil {
	
	private static Random random = new Random();  
	
	public static String getRandomcode(int length) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			if ("char".equalsIgnoreCase(charOrNum)) {
				int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
				sb.append((char)(random.nextInt(26) + temp));
			} else if ("num".equalsIgnoreCase(charOrNum)) {
				sb.append(random.nextInt(10));
			}
		}
		return sb.toString();
	} 
	
	public static void main(String[] args){
		System.out.println(getRandomcode(16));
	}
}
